package com.example.javabasic.thread.classtwo.threadpermessage.demo1;

import java.util.Random;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MessageHandler {
    private static final Random random = new Random(System.currentTimeMillis());
    private final static Executor e = Executors.newFixedThreadPool(5);

    public void request(Message message) {
        e.execute(() -> {
            String value = message.getValue();
            try {
                Thread.sleep(random.nextInt(1000));
                System.out.println(Thread.currentThread().getName()+"请求完成->"+value);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
    }


    public void shutDown(){
        ((ExecutorService) e).shutdown();
    }
}
